/**
 * @filename:AbnormalServiceImpl Jan 16, 2025
 * @project Wonder Vue Admin Api  1.1.0
 * Copyright(c) 2022 Wonder Co. Ltd. 
 * All right reserved. 
 */
package com.wonder.app.service.impl;

import com.wonder.app.domain.Abnormal;
import com.wonder.app.domain.Inspect;
import com.wonder.app.mapper.AbnormalDao;
import com.wonder.app.service.AbnormalService;
import com.wonder.app.request.AbnormalRequest;
import com.wonder.common.utils.StringUtils;
import com.wonder.common.utils.MessageUtils;
import com.wonder.common.common.AjaxResult;

import java.util.*;

import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**   
 * @Description:TODO(异常处理单服务实现)
 *
 * @version: 1.1.0
 * @author: Wonder
 * 
 */
@Service
public class AbnormalServiceImpl  extends ServiceImpl<AbnormalDao, Abnormal> implements AbnormalService  {

    /**
     * 验证异常处理单信息
     * 
     * @param abnormal
     * @param type
     * @return String
     */
    @Override
    public String validate(Abnormal abnormal,String type){
    
    
       return "";
    }
    
    
    /**
	 * Description:异常处理单分页返回
	 * @param request //检索条件
	 * @param page //分页参数
	 * @return IPage<Abnormal>   //分页记录
	 */
	@Override 
	public IPage<Abnormal> selectList(AbnormalRequest request, Page<Abnormal> page){
	    LambdaQueryWrapper<Abnormal> lambdaQueryWrapper = new LambdaQueryWrapper<>();
	    
	    if (null != request.getId()) {
	       lambdaQueryWrapper.eq(Abnormal::getId, request.getId());
	      }
		if (StringUtils.hasText(request.getBillNo())) {
			lambdaQueryWrapper.like(Abnormal::getBillNo, request.getBillNo());
		}
		if (StringUtils.hasText(request.getReceiveBillNo())) {
			lambdaQueryWrapper.like(Abnormal::getReceiveBillNo, request.getReceiveBillNo());
		}
		if (StringUtils.hasText(request.getPurBillNo())) {
			lambdaQueryWrapper.like(Abnormal::getPurBillNo, request.getPurBillNo());
		}
		if (StringUtils.hasText(request.getMaterialNumber())) {
			lambdaQueryWrapper.like(Abnormal::getMaterialNumber, request.getMaterialNumber());
		}
		if (StringUtils.hasText(request.getMaterialName())) {
			lambdaQueryWrapper.like(Abnormal::getMaterialName, request.getMaterialName());
		}
		if (request.getDate() != null) {
			Date[] fCREATEDATE = request.getDate();
			if (fCREATEDATE.length > 0) {
				// 设置开始时间为当天的零点
				Calendar startCalendar = Calendar.getInstance();
				startCalendar.setTime(fCREATEDATE[0]);
				startCalendar.set(Calendar.HOUR_OF_DAY, 0);
				startCalendar.set(Calendar.MINUTE, 0);
				startCalendar.set(Calendar.SECOND, 0);
				startCalendar.set(Calendar.MILLISECOND, 0);
				Date startDate = startCalendar.getTime();
				lambdaQueryWrapper.ge(Abnormal::getDate, startDate);
			}
			if (fCREATEDATE.length == 2) {
				// 设置结束时间为当天的24点
				Calendar endCalendar = Calendar.getInstance();
				endCalendar.setTime(fCREATEDATE[1]);
				endCalendar.set(Calendar.HOUR_OF_DAY, 23);
				endCalendar.set(Calendar.MINUTE, 59);
				endCalendar.set(Calendar.SECOND, 59);
				endCalendar.set(Calendar.MILLISECOND, 999);
				Date endDate = endCalendar.getTime();
				lambdaQueryWrapper.le(Abnormal::getDate, endDate);
			}
		}
		lambdaQueryWrapper.orderByDesc(Abnormal::getId);	
		Page<Abnormal> selectPage = this.baseMapper.selectPage(page, lambdaQueryWrapper);
		return selectPage;
    }
        
    
	
}